import Cookies from 'js-cookie'


//为什么 为什么 Cookie突然不能用了,--md 太长了
const TokenKey = 'Admin-Token-HRM'
const loginUserKey = 'Admin-Login-User'
//var Cookies;
export function getToken () {
  //return Cookies;
  return Cookies.get(TokenKey)
}

export function setToken (token) {
  //return Cookies = token;
  return Cookies.set(TokenKey, token)
}

export function removeToken () {
  //return Cookies = null;

  Cookies.remove(loginUserKey)
  return Cookies.remove(TokenKey)
}
export function loginUser(){
  let res = Cookies.get(loginUserKey);
  if(!res){
    // window.location.href  = '/#/login';
    return null;
  }
  return JSON.parse(res);
}
export function isLogin(){
  let res = Cookies.get(loginUserKey);
  if(!res){

    return false;
  }
  return true;
  // return JSON.parse(res);
}
export function setLoginUser(login){
  return Cookies.set(loginUserKey,JSON.stringify(login))
}
export function getAuthValue(){
  var auths = loginUser().auths;
  // console.info(auths);
  var res = 2;
  for(var i=0;i<auths.length;i++){
    res = Math.min(new Number(auths[i].code[0]),res);
  }
  return res;

}
export function isAdmin(){
  if(!isLogin())return false;
  return getAuthValue()<=1;
}
export function isRoot(){
  if(!isLogin())return false;
  return getAuthValue()==0;
}
